package com.springcloud.utils;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.springcloud.model.DestinationModel;
import okhttp3.Callback;

import java.util.List;


public class HttpClientHelper {
    private static final String OpenTCS_URL = "http://localhost:55200/v1/transportOrders/";
    private static final String WMS_URL = "http://localhost:8084/wds/forklift/callback";

    public static boolean createOrder(String taskno, List<DestinationModel> list) {
        JSONArray jsonArray = new JSONArray();
        if (list != null && list.size() > 0) {
            jsonArray.addAll(list);
        }
       // destinations.add(list);
        //每次订单不能相同，创建随机数
//        Random rd = new Random();
//        int i = rd.nextInt(1000);
//        String s = i + "";

        JSONObject destinations=new JSONObject();
        destinations.put("destinations",jsonArray);
        String temp=destinations.toJSONString();
        String str=HttpPostHelper.syncPostJson(OpenTCS_URL + taskno,temp);
        return str.length() > 0;
    }

    public static void postWMSTask(String taskno,  Callback callback) {
        JSONObject obj = new JSONObject();
        obj.put("id", taskno);
        obj.put("palletNo",1);
        obj.put("status", 2);
        HttpPostHelper.asyncPostJson(WMS_URL,obj.toJSONString() , callback);

    }

}
